package com.sankuai.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author：YH
 * @Description：
 * @Date:Created in 2022/3/4 0:29
 */
@Service
public class ExcuterService {

    private static Logger LOGGER = LoggerFactory.getLogger(ExcuterService.class);

    private ExecutorService cachedThreadPool = Executors.newFixedThreadPool(4);

    public void excute() {
        while (true) {
            cachedThreadPool.execute(getThread());
        }
    }

    public static Runnable getThread() {
        return new Runnable() {
            @Override
            public void run() {
                LOGGER.info("线程id: " + Thread.currentThread().getId());
            }
        };
    }
}
